﻿


$(document).ready(function () {
    $("#submit").click(function (e) {
        var str1 = document.getElementById("username").value;

        if (str1 == null || str1 == "") {
            $("#checkusername").text("用户名不能为空");

        }

        var str2 = document.getElementById("password1").value;

        if (str2 == null || str2 == "") {
            $("#checkpassword1").text("密码不能为空");
        }

        var str3 = document.getElementById("password2").value;

        if (str3 == null || str3 == "") {
            $("#checkpassword2").text("密码不能为空");
        }
        if (!checkstr(str1) || !checkstr(str2) || !checkstr(str3) || str2 != str3) {
            alert("填写错误!");
            e.preventDefault();
        }

    });
});


$(document).ready(function () {


    $("#username").blur(function () {
        var str1 = document.getElementById("username").value;
        if (str1 == null || str1 == "") {
            $("#checkusername").text("用户名不能为空");

        }
    });
    $("#password1").blur(function () {
        var str2 = document.getElementById("password1").value;
        if (str2 == null || str2 == "") {
            $("#checkpassword1").text("密码不能为空");
        }
    });
    $("#password2").blur(function () {
        var str3 = document.getElementById("password2").value;
        if (str3 == null || str3 == "") {
            $("#checkpassword2").text("密码不能为空");
        }
    });

    $("#username").focus(function () {
        $("#checkusername").text("");
    });
    $("#password1").focus(function () {
        $("#checkpassword1").text("");
    });
    $("#password2").focus(function () {
        $("#checkpassword2").text("");
    });


    $("#password1").blur(function () {
        $("#password2").blur(function () {
            var str1 = document.getElementById("password1").value;
            var str2 = document.getElementById("password2").value;
            if (str1 != str2) {
                $("#checkpassword2").text("两次密码不一致!");
            }
        });

    });
});

function checkstr(str) {
    if (str == "" || str == null)
        return false;
    else
        return true;
}

/*
$(document).ready(function () {
    $("#username").blur(function () {
        var username = document.getElementById("username").value;
        if (username == null || username == "") {
            $("#checkusername").text("必须输入用户名");
        }
    });
    $("#password1").blur(function () {
        var password1 = document.getElementById("password1").value;
        if (password1 == null || password1 == "") {
            $("#checkpassword1").text("必须输入密码");
        }
    });
    $("#password2").blur(function () {
        var password2 = document.getElementById("password2").value;
        if (password2 == null || password2 == "") {
            $("#checkpassword2").text("必须输入密码");
        }
    });

    $("#username").focus(function () {
        var username = document.getElementById("username").value;
        if (username == null || username == "") {
            $("#checkusername").text("");
        }
    });
    $("#password1").focus(function () {
        var password1 = document.getElementById("password1").value;
        if (password1 == null || password1 == "") {
            $("#checkpassword1").text("");
        }
    });
    $("#password2").focus(function () {
        var password2 = document.getElementById("password2").value;
        if (password2 == null || password2 == "") {
            $("#checkpassword2").text("");
        }
    });


    $("#password1").blur(function () {
        $("#password2").blur(function (){
            var password1 = document.getElementById("password1").value;
            var password2 = document.getElementById("password2").value;
            if (password1!=password2)
            {
                $("#checkpassword2").text("两次输入的密码不相符!");
            }
        }
        )
    });

    $("#password1").blur(function () {
        $("#password2").blur(function () {
            var password1 = document.getElementById("password1").value;
            var password2 = document.getElementById("password2").value;
            if (password1 == password2) {
                $("#checkpassword2").text("");
            }
        }
        )
    });
});
*/



